﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx
{
    [Serializable]
    public class CameraAdaptConfig
    {
        public float orthographicSize;
        public float fieldOfView;
        public float nearClipPlane;
        public float farClipPlane;
        
        //重写Equals方法
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            CameraAdaptConfig other = (CameraAdaptConfig)obj;
            // Compare orthographicSize properties
            if (Math.Abs(orthographicSize - other.orthographicSize) > 0.001f)
            {
                return false;
            }
            
            if (Math.Abs(fieldOfView - other.fieldOfView) > 0.001f)
            {
                return false;
            }
            
            if (Math.Abs(nearClipPlane - other.nearClipPlane) > 0.001f)
            {
                return false;
            }
            
            if (Math.Abs(farClipPlane - other.farClipPlane) > 0.001f)
            {
                return false;
            }

            return true;
        }
        //重写GetHashCode方法
        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + orthographicSize.GetHashCode();
            hash = hash * 23 + fieldOfView.GetHashCode();
            hash = hash * 23 + nearClipPlane.GetHashCode();
            hash = hash * 23 + farClipPlane.GetHashCode();
            return hash;
        }
    }
    [DisallowMultipleComponent]
    public class CameraAdapt : AdaptBase<CameraAdaptConfig, Camera>
    {
        protected override void CopyProperty(CameraAdaptConfig config) {
            base.CopyProperty(config);
            config.orthographicSize = mComponent.orthographicSize;
            config.fieldOfView = mComponent.fieldOfView;
            config.nearClipPlane = mComponent.nearClipPlane;
            config.farClipPlane = mComponent.farClipPlane;
        }

        protected override void ApplyConfig(CameraAdaptConfig config) {
            base.ApplyConfig(config);
            mComponent.orthographicSize = config.orthographicSize;
            mComponent.fieldOfView = config.fieldOfView;
            mComponent.nearClipPlane = config.nearClipPlane;
            mComponent.farClipPlane = config.farClipPlane;
        }
    }
}
